home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11yt.zip / TEST / TESTIME.C next >
C/C++ Source or Header  |  1992-11-22  |  5KB  |  109 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       Program:    testtime.c           2/29/92                     */
  3. /*       Author:     Andrew H. Derbyshire                             */
  4. /*                   P. O. Box 132                                    */
  5. /*                   Arlington, MA 02174                              */
  6. /*                   Internet: ahd@kew.com                            */
  7. /*       Function:   Test for bug (system hung) in Borland C++ 2.0    */
  8. /*--------------------------------------------------------------------*/
  9.  
  10. /*--------------------------------------------------------------------*/
  11. /*    It appears Borland C++ 2.0 function mktime() hangs on leap      */
  12. /*    day; this program tests that theory.                            */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                       Standard include files                       */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. #include <stdio.h>
  20. #include <time.h>
  21. #include <stdlib.h>
  22.  
  23. /*--------------------------------------------------------------------*/
  24. /*                    Internal (local) prototypes                     */
  25. /*--------------------------------------------------------------------*/
  26.  
  27. void static report( const char *date_string );
  28.  
  29. /*--------------------------------------------------------------------*/
  30. /*    m a i n                                                         */
  31. /*                                                                    */
  32. /*    Main program, of course                                         */
  33. /*--------------------------------------------------------------------*/
  34.  
  35. void main( void )
  36. {
  37.  
  38. /*--------------------------------------------------------------------*/
  39. /*                       Announce our existence                       */
  40. /*--------------------------------------------------------------------*/
  41.  
  42.    printf("testtime.c: Copyright (c) 1992 by Andrew H. Derbyshire\n"
  43.           "May be distributed freely if no money is charged for the\n"
  44.           "program and source is included\n\n");
  45.  
  46. /*--------------------------------------------------------------------*/
  47. /*                         Run the test cases                         */
  48. /*--------------------------------------------------------------------*/
  49.  
  50.    report("date 02/28/92");
  51.  
  52.    report("date 03/01/92");
  53.  
  54.    report("date 02/29/92");         /* Fails on this call            */
  55.  
  56.    report("rem");                   /* Current date                  */
  57.  
  58. } /* main */
  59.  
  60. /*--------------------------------------------------------------------*/
  61. /*    r e p o r t                                                     */
  62. /*                                                                    */
  63. /*    Process one test case (date)                                    */
  64. /*--------------------------------------------------------------------*/
  65.  
  66. void static report( const char *date_string )
  67. {
  68.    struct tm  *time_record;
  69.    time_t secs = time( NULL );
  70.    time_t save;
  71.  
  72. /*--------------------------------------------------------------------*/
  73. /*                       Save real system time                        */
  74. /*--------------------------------------------------------------------*/
  75.  
  76.    time(&save);
  77.  
  78. /*--------------------------------------------------------------------*/
  79. /*             Set DOS system date through SYSTEM command             */
  80. /*--------------------------------------------------------------------*/
  81.  
  82.    printf("Executing command: %s\n",date_string);
  83.    system(date_string);
  84.  
  85. /*--------------------------------------------------------------------*/
  86. /*                         Get adjusted time                          */
  87. /*--------------------------------------------------------------------*/
  88.  
  89.    time( &secs ) ;
  90.    time_record = localtime(&secs);
  91.  
  92. /*--------------------------------------------------------------------*/
  93. /*                           Restore clock                            */
  94. /*--------------------------------------------------------------------*/
  95.  
  96.    stime( &save );
  97.  
  98. /*--------------------------------------------------------------------*/
  99. /*                      Display the altered time                      */
  100. /*--------------------------------------------------------------------*/
  101.  
  102.    printf("Input time:\t%s",ctime( &secs ));
  103.  
  104.    secs = mktime(time_record);   /* This call HANGS on 02/29/92      */
  105.  
  106.    printf("Output time:\t%s\n",ctime( &secs ));
  107.  
  108. } /* report */
  109.